<!DOCTYPE html>
<html>
<head>
<title>Document.createElement() and Document.createElementNS() create custom element of type, specified by localName argument</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="If an element definition with matching localName, namespace, and TYPE is not registered with token's document, set TYPE to localName">
<link rel="help" href="http://www.w3.org/TR/custom-elements/#extensions-to-document-interface-to-instantiate">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../testcommon.js"></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script>
test (function() {
    var doc = newHTMLDocument();
    HTML5_ELEMENTS.forEach(function(tagName) {
        var obj = doc.createElement(tagName);
        var name = 'x-a-' + tagName;
        var proto = Object.create(obj.constructor.prototype);
        var customElement = doc.createElement(tagName, name);
        assert_equals(Object.getPrototypeOf(customElement), Object.getPrototypeOf(obj),
            'Unregistered custom element type should be a local name');

        var GeneratedConstructor = doc.registerElement(name, {prototype: proto, extends: tagName});
        assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
            'Registered custom element type should be the type extension');
    });
}, 'If typeExtension is unresolved when createElement called then local name is a type');


test (function() {
    var doc = newHTMLDocument();
    HTML5_ELEMENTS.forEach(function(tagName) {
        var obj = doc.createElement(tagName);
        var name = 'x-b-' + tagName;
        var proto = Object.create(obj.constructor.prototype);
        var customElement = doc.createElementNS(HTML_NAMESPACE, tagName, name);
        assert_equals(Object.getPrototypeOf(customElement), Object.getPrototypeOf(obj),
            'Custom element type should be a local name');

        var GeneratedConstructor = doc.registerElement(name, {prototype: proto, extends: tagName});
        assert_equals(Object.getPrototypeOf(customElement), GeneratedConstructor.prototype,
            'Custom element type should be the type extension');
    });
}, 'If typeExtension is unresolved when createElementNS called then local name is a type');
</script>
</body>
</html>
